package com.vcredit.creditcat.web.app;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.ICustManager;
import com.vcredit.creditcat.api.IMobileProcessManager;
import com.vcredit.creditcat.dto.mobile.MobileProcessInDto;
import com.vcredit.creditcat.dto.mobile.MobileProcessOutDto;
import com.vcredit.creditcat.dto.mobile.MobileProcessStatus;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.vo.MobileResultOut;
import com.vcredit.framework.annotation.Log;

@Controller
@RequestMapping(value = "/mobile")
public class MobileProcessController extends BaseCreditCatController {

	@Reference(version = "1.0")
	private IMobileProcessManager mobileProcessManager;

	@Reference(version = "1.0")
	private ICustManager custManager;

	/***
	 * 手机认证-初始化
	 * 
	 * @param mobileProcessInDto
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/init")
	@ResponseBody
	@Log
	public MobileResultOut mobileInit(MobileProcessInDto mobileProcessInDto, HttpServletRequest request)
			throws Exception {
		Cust cust = custManager.findById(super.getCust(request).getCustId());
		MobileProcessOutDto ret = mobileProcessManager.mobileInit(mobileProcessInDto, cust);
		MobileResultOut result = new MobileResultOut();
		BeanUtils.copyProperties(result, ret);
		return result;
	}

	/***
	 * 手机认证-登录,使用手机号与服务密码登录运营商平台获取用户信息
	 * 
	 * @param mobileProcessInDto
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping(value = "/login")
	@ResponseBody
	public MobileResultOut mobileLogin(MobileProcessInDto mobileProcessInDto, HttpServletRequest request)
			throws Exception {
		Cust cust = custManager.findById(super.getCust(request).getCustId());
		MobileProcessOutDto ret = mobileProcessManager.mobileLogin(mobileProcessInDto, cust);
		if (ret.getNextProCode().equals("5") || ret.getNextProCode().equals("7")) {
			ret = mobileProcessManager.mobileSendSms(mobileProcessInDto, cust);
		}
		MobileResultOut result = new MobileResultOut();
		BeanUtils.copyProperties(result, ret);
		return result;
	}

	@Log
	@RequestMapping(value = "/sendSms")
	@ResponseBody
	public MobileResultOut mobileSendSms(MobileProcessInDto mobileProcessInDto, HttpServletRequest request)
			throws Exception {
		Cust cust = custManager.findById(super.getCust(request).getCustId());
		MobileProcessOutDto ret = mobileProcessManager.mobileSendSms(mobileProcessInDto, cust);
		MobileResultOut result = new MobileResultOut();
		BeanUtils.copyProperties(result, ret);
		return result;
	}

	@Log
	@RequestMapping(value = "/checkSms")
	@ResponseBody
	public MobileResultOut mobileCheckSms(MobileProcessInDto mobileProcessInDto, HttpServletRequest request)
			throws Exception {
		Cust cust = custManager.findById(super.getCust(request).getCustId());
		MobileProcessOutDto ret = mobileProcessManager.mobileCheckSms(mobileProcessInDto, cust);
		MobileResultOut result = new MobileResultOut();
		BeanUtils.copyProperties(result, ret);
		return result;
	}

	@Log
	@RequestMapping(value = "/getStatus")
	@ResponseBody
	public MobileProcessStatus getStatus(MobileProcessInDto mobileProcessInDto,HttpServletRequest request) throws Exception {
		Cust cust = custManager.findById(super.getCust(request).getCustId());
		MobileProcessStatus result = mobileProcessManager.getStatus(cust);
		return result;
	}

	@Log
	@RequestMapping(value = "/getWebSite")
	@ResponseBody
	public MobileResultOut getWebSite(MobileProcessInDto mobileProcessInDto, HttpServletRequest request)
			throws Exception {
		Cust cust = custManager.findById(super.getCust(request).getCustId());
		MobileProcessOutDto ret = mobileProcessManager.getWebSite(mobileProcessInDto, cust);
		MobileResultOut result = new MobileResultOut();
		BeanUtils.copyProperties(result, ret);
		return result;
	}

	/**
	 * 保存通话记录
	 * 
	 * @param callLogDto
	 * @param request
	 * @return
	 * @throws Exception
	 */

	
}
